﻿
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.GraphicsSystem;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using XS.Tunnel.Cad.SteelBracing.BusinessExtensions;
using XS.Tunnel.Cad.SteelBracing.Infrastructure;
using XS.Tunnel.Cad.SteelBracing.Infrastructure.Extensions;
using XS.Tunnel.Cad.SteelBracing.Infrastructure.Helper;

namespace XS.Tunnel.Cad.SteelBracing.Component.SteelShotcrete.UniversalBeamComponent
{
    public class UniversalBeamBuild : AbstractSteelShotcrete
    {

        public UniversalBeamParam universalBeamParam { get; set; }

        public UniversalBeamBuild(DarkHoleInfo info, IList<ISysPoint> pointData, SteelShotcreteParameter parameter) : base(info, pointData, parameter)
        {
        }


        public Dictionary<ContourLineType, List<Curve>> ArchRingContour { get; private set; }=new Dictionary<ContourLineType, List<Curve>>();
        public Dictionary<ContourLineType, List<Curve>> InvertedArchContour { get; private set; }= new Dictionary<ContourLineType, List<Curve>>();    



        protected override void Initial()
        {
            universalBeamParam=Parameter as UniversalBeamParam;

            var mainArc = Arc180Split(ArchRing.ArchRingRetract(universalBeamParam.ShrinkSize));

            RightSideAll = mainArc.RightSideAll;
            Arc180 = mainArc.ArcSplit;
            LeftSideAll = mainArc.LeftSideAll;
            Subsections = mainArc.ArcSplits;
            SteelPlateInit();

        }

        private void SteelPlateInit()
        {
            if (universalBeamParam.Middle != null)
            {
                universalBeamParam.Middle.SteelType = SteelType.Middle;
            }
            if (universalBeamParam.WallFoot != null)
            {
                universalBeamParam.WallFoot.SteelType = SteelType.WallFoot;
            }
            if (universalBeamParam.InvertedJoinWallFoot != null)
            {
                universalBeamParam.InvertedJoinWallFoot.SteelType = SteelType.InvertedJoinWallFoot;
            }


        }



        public override void Draw()
        {

            foreach (var curve in ArchRingContour) {

                foreach (var item in curve.Value)
                {
                    if (curve.Key == ContourLineType.DottedContour)
                    {
                        item.Color = "#ffff00".ToColor();
                    }
                    else
                    {
                        item.Color = "#00ff00".ToColor(); 
                    }
                    Drawing(item);
                }
            }
            foreach (var curve in InvertedArchContour)
            {
                foreach (var item in curve.Value)
                {
                    if (curve.Key == ContourLineType.DottedContour)
                    {
                        item.Color = "#ffff00".ToColor();
                    }
                    else
                    {
                        item.Color = "#00ff00".ToColor();
                    }
                    Drawing(item);
                }
            }


            //创建钢板
            foreach (var line in SteelPlateList)
            {
                line.Color = "#FF00FF".ToColor();
                Drawing(line);
            }
        }

        public override void Build()
        {
            // 初期支护外轮廓
            //var ll = ArchRing.ToEntitys();
            //Drawing(ll);

            var dummyLine = ArchRing.ArchRingRetract(universalBeamParam.ShrinkSize).ToPolyline();
            var newDummyLine = dummyLine.Split(universalBeamParam.WallFoot.Thickness, dummyLine.GetLength() - universalBeamParam.WallFoot.Thickness);
            ArchRingContour.Add(ContourLineType.DottedContour, new List<Curve> { newDummyLine });

            var outerContour = Arc180Split(ArchRing.ArchRingRetract(universalBeamParam.WallInterval));
            var innerContour = Arc180Split(ArchRing.ArchRingRetract(universalBeamParam.InnerShrinkSize));

            ArchRingContour.Add(ContourLineType.OuterContour, outerContour.TotalArc);
            ArchRingContour.Add(ContourLineType.InnerContour, innerContour.TotalArc);
            if (Info.IsSetInvertedArch)
            {
                //仰拱
                CreatInvertedArch();
                InvertedArchAddSteelPlate();

            }
          
            //添加钢板
            AddSteelPlate();
            AddWallFootSteelPlate(outerContour, innerContour);
        }

        /// <summary>
        /// 创建仰拱
        /// </summary>
        private void CreatInvertedArch()
        {
            // 判断是否是大拐角的
            if (Info.ColumnArchFootType == ColumnArchFootType.LargeCornerJoin)
            {
                CreateLargeCornerJoin();
                return;
            }


            var dummyLine = InvertedArchPath.InvertedArchRetract(universalBeamParam.ShrinkSize);
            var outerContour =InvertedArchPath.ArchRingRetract(universalBeamParam.WallInterval);
            var innerContour = InvertedArchPath.ArchRingRetract(universalBeamParam.InnerShrinkSize);

            if (dummyLine.Count == 1)
            {
                var line = OneInvertedArc(dummyLine.FirstOrDefault(), ContourLineType.DottedContour);
                var outerLine = OneInvertedArc(outerContour.FirstOrDefault(), ContourLineType.OuterContour);
                var innerLine = OneInvertedArc(innerContour.FirstOrDefault(), ContourLineType.InnerContour);
                AddSidSteelPlate(outerLine, innerLine);
            }
            else if (dummyLine.Count == 3)
            {
               var line=  ThreeInvertedArc(dummyLine, ContourLineType.DottedContour);
               var outerLine= ThreeInvertedArc(outerContour, ContourLineType.OuterContour);
               var innerLine= ThreeInvertedArc(innerContour,ContourLineType.InnerContour);
               AddSidSteelPlate(outerLine,innerLine);
            }
            else
            {
                return;
            }
        }


        /// <summary>
        /// 大墙角 仰拱
        /// </summary>
        private void CreateLargeCornerJoin()
        {
           
            var dummyLine = InvertedArchPath.InvertedArchRetract(universalBeamParam.ShrinkSize);
            var outerContour = InvertedArchPath.InvertedArchRetract(universalBeamParam.WallInterval);
            var innerContour = InvertedArchPath.InvertedArchRetract(universalBeamParam.InnerShrinkSize);

            var dummyLineInvertedArch= CreateLargeCornerInvertedArch(dummyLine,ContourLineType.DottedContour);
            var outerContourInvertedArch = CreateLargeCornerInvertedArch(outerContour, ContourLineType.OuterContour);
            var innerContourInvertedArch = CreateLargeCornerInvertedArch(innerContour, ContourLineType.InnerContour);

            InvertedArc = dummyLineInvertedArch.Vault;

            InvertedArchContour.Add(ContourLineType.OuterContour, outerContourInvertedArch.ToList(SplitInvertedArch(innerContourInvertedArch.Vault)));
            InvertedArchContour.Add(ContourLineType.InnerContour, innerContourInvertedArch.ToList(SplitInvertedArch(outerContourInvertedArch.Vault)));
            InvertedArchContour.Add(ContourLineType.DottedContour, dummyLineInvertedArch.ToList(new List<Curve> { dummyLineInvertedArch.Vault }));


            var left = new Line(innerContourInvertedArch.LeftEndPoint,outerContourInvertedArch.LeftEndPoint);
            var right = new Line(innerContourInvertedArch.RightEndPoint, outerContourInvertedArch.RightEndPoint);

            //计算出 (脚钢长- 工字钢的宽 )/2 就是 两边延长多长
            var l = (universalBeamParam.InvertedJoinWallFoot.Length - left.Length) / 2;
            var rightL = right.ToBothSidesLengthen(l);
            var leftL = left.ToBothSidesLengthen(l);

            var d1 = new SteelPlateComponent(universalBeamParam.InvertedJoinWallFoot).CreateSidSteelPlate(rightL, false);
            var d2 = new SteelPlateComponent(universalBeamParam.InvertedJoinWallFoot).CreateSidSteelPlate(leftL);

            SteelPlateList.Add(d1);
            SteelPlateList.Add(d2);
        }

       

       




        public InvertedArchLine CreateLargeCornerInvertedArch(List<ISysPoint> list, ContourLineType type)
        {
            var centre = list.Where(x => x.Code == StructurePointLocationConstant.InvertedArchArc).FirstOrDefault().ToCurve();
            var left = list.Where(x => x.Code == StructurePointLocationConstant.LeftHorizon).FirstOrDefault().ToCurve().Reversal();
            var right = list.Where(x => x.Code == StructurePointLocationConstant.RightHorizon).FirstOrDefault().ToCurve();

           
            //Drawing(InvertedArchPath.ToEntitys());

            //Drawing(LeftSideAllLine.RightMove(universalBeamParam.ShrinkSize * 2));

            var leftPoint = left.IntersectPoint(LeftSideAllLine.LineMove(-universalBeamParam.InnerShrinkSize), Intersect.ExtendBoth);
            var rightPoint = right.IntersectPoint( RightSideAllLine.LineMove(-universalBeamParam.InnerShrinkSize), Intersect.ExtendBoth);

            var lineLeft = new Line(centre.StartPoint, leftPoint);
            var lineRight = new Line(centre.EndPoint, rightPoint);

            if (type == ContourLineType.DottedContour)
            {
                return new InvertedArchLine(lineLeft, lineRight, centre);
            }
            var ll1 = centre.VerticalLine(centre.StartPoint,0.5);
            var ll2 = ll1.VerticalLine(centre.StartPoint, universalBeamParam.Middle.GetUnilateral() );
            // 向两侧延伸 1000 为了交点
            var lVT = ll2.VerticalLine(ll2.EndPoint,0.5).ToBothSidesLengthen(1000);
            var lStart = lineLeft.Reversal().IntersectPoint(lVT);
            var lEnd = lineLeft.GetPointAtDist(lineLeft.GetLength()-universalBeamParam.InvertedJoinWallFoot.GetUnilateral());


            var rl1 = centre.VerticalLine(centre.EndPoint, 0.5);
            var rl2 = rl1.VerticalLine(centre.EndPoint, -universalBeamParam.Middle.GetUnilateral());
            // 向两侧延伸 1000 为了交点
            var rVT = rl2.VerticalLine(rl2.EndPoint, 0.5).ToBothSidesLengthen(1000);

            var rStart = lineRight.IntersectPoint(rVT);// lineRight.GetPointAtDist(universalBeamParam.Middle.GetUnilateral());
            var rEnd = lineRight.GetPointAtDist(lineRight.GetLength() - universalBeamParam.InvertedJoinWallFoot.GetUnilateral());

            return new InvertedArchLine(new Line(lStart,lEnd), new Line(rStart,rEnd), centre);
        }




        /// <summary>
        /// 仰拱只有一个弧的时候
        /// </summary>
        private Line OneInvertedArc(ISysPoint centre, ContourLineType type) {

            var arc = centre.ToCurve() as Arc;
            var p = ArcLengthen(arc);
            List<Curve> splits = null;
            if (type == ContourLineType.DottedContour)
            {
                splits = new List<Curve> { arc };
                InvertedArc = arc;
            }
            else
            {
                splits = SplitInvertedArch(arc,false);
            }
          
            var curves = new List<Curve>();

            var leftL = new Line(arc.StartPoint, p.Left);
            var rightL=new Line(arc.EndPoint, p.Right);

            var leftAngle = 180 * leftL.GetLength() / (Math.PI * arc.Radius);
            var rightAngle = 180 * rightL.GetLength() / (Math.PI * arc.Radius);
            var leftArc = new Arc(arc.Center, arc.Radius, arc.StartAngle - leftAngle.DegreeToAngle(), arc.StartAngle);
            var rightArc = new Arc(arc.Center, arc.Radius, arc.EndAngle, arc.EndAngle+ rightAngle.DegreeToAngle());

            curves.AddRange(splits);
            curves.Add(leftArc);
            curves.Add(rightArc);

            InvertedArchContour.Add(type, curves);

            return new Line(p.Left, p.Right);
        }
        /// <summary>
        /// 3段弧的仰拱 
        /// </summary>
        private Line ThreeInvertedArc(List<ISysPoint> list, ContourLineType type)
        {

            var left = list.Where(x => x.Code == StructurePointLocationConstant.LeftInvertedArchArc).FirstOrDefault();
            var right = list.Where(x => x.Code == StructurePointLocationConstant.RightInvertedArchArc).FirstOrDefault();
            var centre = list.Where(x => x.Code == StructurePointLocationConstant.InvertedArchArc).FirstOrDefault().ToCurve();
            

            Curve leftCurve= left.ToCurve();
            Curve rightCurve= right.ToCurve();
            var p = LeftAndRightArcLengthen(leftCurve, rightCurve);

            if (p.Left == null || p.Right==null)
            {
                return null;
            }
            var leftL = new Line(leftCurve.StartPoint, p.Left);
            var rightL = new Line(rightCurve.EndPoint, p.Right);

            List<Curve> splits = null;
            if (type == ContourLineType.DottedContour)
            {
                splits = new List<Curve> { centre };
                LeftInvertedArc = leftCurve;
                RightInvertedArc = rightCurve;
                InvertedArc = centre;
            }
            else
            {
                splits = SplitInvertedArch(centre);
            }
           


            var ll = leftCurve.Split(leftCurve.GetLength() - universalBeamParam.Middle.GetUnilateral());
            var rl = rightCurve.Split(universalBeamParam.Middle.GetUnilateral(), true);

            var curves = new List<Curve>
            {
                leftL,rightL,
            };

            if (type == ContourLineType.DottedContour)
            {
                curves.Add(leftCurve);
                curves.Add(rightCurve);
            }
            else
            {
                curves.Add(ll);
                curves.Add(rl);
            }

            curves.AddRange(splits);
            InvertedArchContour.Add(type, curves);
            return new Line(p.Left, p.Right);

        }

        /// <summary>
        /// 左右弧的切线延长线
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <returns></returns>
        private LeftAndRightPoint LeftAndRightArcLengthen(Curve left, Curve right)
        {
            Curve leftCurve;
            Curve rightCurve;

            //左边交点集合
            Point3dCollection leftPList = new Point3dCollection();//交点集合
            //右边交点集合
            Point3dCollection rightPList = new Point3dCollection();//交点集合
           

            if (left is Arc)
            {
                var leftArc = left  as Arc;
                var rightArc = right as Arc;

                var leftvt = leftArc.GetFirstDerivative(leftArc.StartPoint);
                leftvt.GetNormal();

                var rightvt = rightArc.GetFirstDerivative(rightArc.EndPoint);
                rightvt.GetNormal();
                //为了求交点
                leftCurve = new Line(leftArc.StartPoint, leftArc.StartPoint.Add(leftvt * 0.5));
                rightCurve = new Line(rightArc.EndPoint, rightArc.EndPoint.Add(rightvt * 0.5));

            }
            else  // 左右圆弧可能是直线
            {
                var leftL= left as Line; 
                var rightL = right as Line;
                leftCurve = new Line(leftL.EndPoint, leftL.StartPoint);
                rightCurve = rightL;
            }
            // 斜着的钢板厚度
            var thickness = universalBeamParam.InvertedJoinWallFoot.GetUnilateral();

            //var leftIntersectLine= new Line(new Point3d(LeftSideAllLine.StartPoint.X + thickness+ universalBeamParam.ShrinkSize, LeftSideAllLine.StartPoint.Y, 0), new Point3d(LeftSideAllLine.EndPoint.X + thickness + universalBeamParam.ShrinkSize, LeftSideAllLine.EndPoint.Y, 0));
            //var rightIntersectLine = new Line(new Point3d(RightSideAllLine.StartPoint.X - thickness- universalBeamParam.ShrinkSize, RightSideAllLine.StartPoint.Y, 0), new Point3d(RightSideAllLine.EndPoint.X - thickness - universalBeamParam.ShrinkSize, RightSideAllLine.EndPoint.Y, 0));


            var interval = universalBeamParam.InnerShrinkSize + thickness;
            var leftIntersectLine = LeftSideAllLine.LineMove(-interval);
            var rightIntersectLine = RightSideAllLine.LineMove(-interval);


            // 求交点
            leftCurve.IntersectWith(leftIntersectLine, Intersect.ExtendThis, leftPList, 0, 0);
            rightCurve.IntersectWith(rightIntersectLine, Intersect.ExtendThis, rightPList, 0, 0);

            if (leftPList.Count <= 0 || rightPList.Count <= 0)
            {
                Alert("数据计算异常");
                return null;
            }

            return LeftAndRightPoint.Create(leftPList[0], rightPList[0]);
        }

        /// <summary>
        /// 弧延长线
        /// </summary>
        /// <returns></returns>
        private LeftAndRightPoint ArcLengthen(Curve arc)
        {

            //左边交点集合
            Point3dCollection leftPList = new Point3dCollection();//交点集合
            //右边交点集合
            Point3dCollection rightPList = new Point3dCollection();//交点集合
            // 斜着的钢板厚度
            var thickness = universalBeamParam.InvertedJoinWallFoot.GetUnilateral();
            //var leftIntersectLine = new Line(new Point3d(LeftSideAllLine.StartPoint.X + thickness + universalBeamParam.ShrinkSize, LeftSideAllLine.StartPoint.Y, 0), new Point3d(LeftSideAllLine.EndPoint.X + thickness + universalBeamParam.ShrinkSize, LeftSideAllLine.EndPoint.Y, 0));
            //var rightIntersectLine = new Line(new Point3d(RightSideAllLine.StartPoint.X - thickness - universalBeamParam.ShrinkSize, RightSideAllLine.StartPoint.Y, 0), new Point3d(RightSideAllLine.EndPoint.X - thickness - universalBeamParam.ShrinkSize, RightSideAllLine.EndPoint.Y, 0));


            var interval = universalBeamParam.InnerShrinkSize + thickness;
            var leftIntersectLine = LeftSideAllLine.LineMove(-interval);
            var rightIntersectLine = RightSideAllLine.LineMove(-interval);



          //右边的交点
          arc.IntersectWith(rightIntersectLine, Intersect.ExtendThis, rightPList, 0, 0);

            arc.IntersectWith(leftIntersectLine, Intersect.ExtendThis, leftPList, 0, 0);

            if (leftPList.Count <= 0 || rightPList.Count <= 0)
            {
                Alert("数据计算异常");
                return null;
            }
            var lp = leftPList[leftPList.Count - 1];
            var rp = rightPList[0];

            return LeftAndRightPoint.Create(lp, rp);        
        }


        /// <summary>
        /// 侧方钢板   仰拱链接墙脚钢板 斜的 只有全断面才会右
        /// </summary>
        private void AddSidSteelPlate(Line outerLine,Line innerLine)
        {
            //universalBeamParam.InvertedJoinWallFoot

            var left = new Line(innerLine.StartPoint,outerLine.StartPoint);
            var right = new Line(innerLine.EndPoint, outerLine.EndPoint);


            //计算出 (脚钢长- 工字钢的宽 )/2 就是 两边延长多长
            var l = (universalBeamParam.InvertedJoinWallFoot.Length - left.Length) / 2;
            var rightL = right.ToBothSidesLengthen(l);
            var leftL = left.ToBothSidesLengthen(l);

            var d1 = new SteelPlateComponent(universalBeamParam.InvertedJoinWallFoot).CreateSidSteelPlate(rightL,false);
            var d2 = new SteelPlateComponent(universalBeamParam.InvertedJoinWallFoot).CreateSidSteelPlate(leftL);

            SteelPlateList.Add(d1);
            SteelPlateList.Add(d2);

        }

       


        /// <summary>
        /// 仰拱分割
        /// </summary>
        /// <param name="arc"></param>
        /// <returns></returns>
        private List<Curve> SplitInvertedArch(Curve curve,bool isSplitFirstOrLast=true)
        {

            var arc = curve as Arc;

            var avgLenght = arc.GetLength() / universalBeamParam.InvertedArchSubsection;
            var p = new Point3dCollection();

            double accumulate = avgLenght;
            var xc = universalBeamParam.Middle.GetUnilateral();


             var r= arc.Radius;
            var n = Math.Asin(xc / r).AngleToDegree();
             var ml = n/360*2*Math.PI*r;



            for (int i = 0; i < universalBeamParam.InvertedArchSubsection; i++)
            {
                if (i == 0 && isSplitFirstOrLast)
                {
                    p.Add(arc.GetPointAtDist(ml));
                }

                if (i == universalBeamParam.InvertedArchSubsection - 1 &&!isSplitFirstOrLast)
                {
                    p.Add(arc.GetPointAtDist(accumulate));
                }
                else
                {
                    p.Add(arc.GetPointAtDist(accumulate - ml));
                }
              
                if (i != universalBeamParam.InvertedArchSubsection - 1)
                {
                    p.Add(arc.GetPointAtDist(accumulate + ml));
                }
              
                accumulate += avgLenght;
            }
            var listSubsection = arc.GetSplitCurves(p).Cast<Curve>().ToList();

            var arcSplit = new List<Curve>();
            for (int i = 0; i < listSubsection.Count; i++)
            {
                if (isSplitFirstOrLast)
                {
                    if (i % 2 != 0)
                    {
                        arcSplit.Add(listSubsection[i] as Curve);
                    }
                }
                else
                {
                    if (i % 2 == 0)
                    {
                        arcSplit.Add(listSubsection[i] as Curve);
                    }
                }
            }
            return arcSplit;

        }


        /// <summary>
        /// 分割拱圈
        /// </summary>
        /// <param name="arc"></param>
        /// <returns>rightSideAll,arc180,leftSideAll, arc180Split</returns>
        private SplitArc Arc180Split(List<ISysPoint> arc)
        {

            var newArc= arc.ToPolyline();

            var point0 = arc.GetByDegrees(0);
            var point180 = arc.GetByDegrees(180);
            if (point0 == null || point180 == null)
            {
                throw XSException.Oh("坐标计算错误");
            }
            var startPoint = point0.Value;
            var endPoint = point180.Value;

            var list= newArc.GetSplitCurves(new Point3dCollection { startPoint, endPoint }).Cast<Curve>().ToList();

            var arc180 = list[1];
            var leftL = list[2] ;
            var rightL = list[0];

            //两边的拱墙的两端都有　钢板
            var leftSideAll = leftL.Split(universalBeamParam.Middle.GetUnilateral(), leftL.GetLength()-universalBeamParam.WallFoot.GetUnilateral());
            var rightSideAll = rightL.Split(universalBeamParam.WallFoot.GetUnilateral(), rightL.GetLength()- universalBeamParam.Middle.GetUnilateral());
           
            //平均长度
            var avgLenght = arc180.GetLength() / universalBeamParam.Subsection;
            var arcs = new Point3dCollection();

            double accumulate = avgLenght;
            var ml = universalBeamParam.Middle.GetUnilateral();
            for (int i = 0; i < universalBeamParam.Subsection; i++)
            {
                if (i == 0)
                {
                    arcs.Add(arc180.GetPointAtDist(ml));
                }
                arcs.Add(arc180.GetPointAtDist(accumulate - ml));
                if (i != universalBeamParam.Subsection - 1)
                {
                    arcs.Add(arc180.GetPointAtDist(accumulate + ml));
                }

                accumulate += avgLenght;
            }
            var listSubsection = arc180.GetSplitCurves(arcs).Cast<Curve>().ToList();
         
            var arc180Split=new List<Curve>();
            var  ds= listSubsection.Cast<Curve>();
            int n = 0;
            foreach (Curve curve in ds)
            {
                if (n % 2 != 0)
                {
                    arc180Split.Add(curve);
                }
                n++;
            }

            return new SplitArc(rightSideAll,arc180,leftSideAll, arc180Split);
        }

        /// <summary>
        /// 仰拱钢板
        /// </summary>
        private void InvertedArchAddSteelPlate()
        {
            InvertedArcSubsections = InvertedArc.ArcSplit(universalBeamParam.InvertedArchSubsection);

            //仰拱由几个弧组成的
            var n = InvertedArchPath.Count;
            //InvertedArcSubsections
            for (int i = 0; i < InvertedArcSubsections.Count; i++)
            {
                if (i == 0 && n==1) continue;
                var item= InvertedArcSubsections[i];
                item.Color = "#00ff00".ToColor();

                var vt1 = item.GetFirstDerivative(item.StartPoint);
                var cp1 = vt1.GetPerpendicularVector();
                cp1 = cp1.GetNormal();

                var l = universalBeamParam.Middle.Length / 2;
                // 上下各一半
                Point3d startPoint = item.StartPoint.Add(cp1 * -l);
                Point3d endPoint = item.StartPoint.Add(cp1 * l);
                var line = new Line(startPoint, endPoint);
                var d = line.CreateSteelPlate(universalBeamParam.Middle);
                SteelPlateList.AddRange(d);
            }

            if (n > 1)
            {
                // 给结束位置加
                var lastLine = InvertedArcSubsections.LastOrDefault();

                var p1 = lastLine.EndPoint;
                var cv = lastLine.GetFirstDerivative(p1);
                var cpv = cv.GetPerpendicularVector().GetNormal();

                var l0 = universalBeamParam.Middle.Length / 2;
                var start1 = p1.Add(cpv * -l0);
                var end1 = p1.Add(cpv * l0);
                var line1 = new Line(start1, end1);
                line1.Color = "#FF00FF".ToColor();
                SteelPlateList.AddRange(line1.CreateSteelPlate(universalBeamParam.Middle));
            }

           
        }

        /// <summary>
        /// 钢板绘制
        /// </summary>
        private void AddSteelPlate()
        {
            var avgLenght = Arc180.GetLength() / universalBeamParam.Subsection;

            var myDis = avgLenght;
            for (int i = 0; i < universalBeamParam.Subsection; i++)
            {
                //获取距离起点 mydis 的多段线上的一个点
                Point3d point = Arc180.GetPointAtDist(myDis);
                Vector3d curVector = Arc180.GetFirstDerivative(point);
                Vector3d curPervector = curVector.GetPerpendicularVector();
                curPervector = curPervector.GetNormal();
                var l= universalBeamParam.Middle.Length/2;
                // 上下各一半
                Point3d startPoint = point.Add(curPervector * -l);
                Point3d endPoint = point.Add(curPervector*l);
                var line = new Line(startPoint, endPoint);
                line.ColorIndex = 1;
                SteelPlateList.AddRange(line.CreateSteelPlate(universalBeamParam.Middle));
              
                myDis = myDis + avgLenght;  // 间隔递增
            }
            // 给开始位置加
            var p1 = Arc180.StartPoint;
            var cv = Arc180.GetFirstDerivative(p1);
            var cpv  = cv.GetPerpendicularVector().GetNormal();

            var l0 = universalBeamParam.Middle.Length / 2;
            var start1 = p1.Add(cpv * -l0);
            var end1 = p1.Add(cpv * l0);
            var line1 = new Line(start1, end1);
            SteelPlateList.AddRange(line1.CreateSteelPlate(universalBeamParam.Middle));

        }

        /// <summary>
        /// 墙脚链接钢板
        /// </summary>
        private void AddWallFootSteelPlate(SplitArc outer,SplitArc inner)
        {
            var left = new Line(outer.LeftSideAll.EndPoint, inner.LeftSideAll.EndPoint);
            var right = new Line(inner.RightSideAll.StartPoint, outer.RightSideAll.StartPoint);
            //计算出 (脚钢长- 工字钢的宽 )/2 就是 两边延长多长
            var l= (universalBeamParam.WallFoot.Length-left.Length)/2;
            var rightL = right.ToBothSidesLengthen(l);
            var leftL= left.ToBothSidesLengthen(l);

            SteelPlateList.Add(new SteelPlateComponent(universalBeamParam.WallFoot).CreateWallFoot(rightL));
            SteelPlateList.Add(new SteelPlateComponent(universalBeamParam.WallFoot).CreateWallFoot(leftL));
        }

    }


}
